.SUFFIXES : .cu .cubin

CUDA_INSTALL_PATH ?= /usr/local/cuda

# compiler names:
# Compilers
NVCC       := nvcc
CXX        := g++
CC         := gcc
LINK       := g++ -fPIC

# flags for C++ compiler:
CFLAGS		= -g -Wall -DCUDA_SUPPORT #-DDEBUGCALC #-DDEBUG

CUDA_SDK_DIR		= $(HOME)/NVIDIA_GPU_Computing_SDK
CUDA_INSTALL_PATH	= /usr/local/cuda
CUBIN_ARCH_FLAG 	= -m32
CUBINDIR 		= .
SRCDIR			= .

NVCCFLAGS		= -arch sm_11 -use_fast_math

INCFLAGS		= 	-I. \
				-I./CudaKernels \
				-I./RadixSort \
				-I./Scan \
				-I./Visualizacao \
				-I./Inicializacao \
				-I$(CUDA_INSTALL_PATH)/include \
				-I$(CUDA_SDK_DIR)/C/common/inc \


# libraries to link with:

LIBPATH = 	-L$(CUDA_INSTALL_PATH)/lib \
		-L$(CUDA_SDK_DIR)/C/lib \
		-L$(CUDA_SDK_DIR)/C/common/lib/linux

LDFLAGS = -lGL -lGLU -lglut -lGLEW

CUDPPLIB = -lcudart -lcutil -lcudpp

OBJFILES = main.o CudaKernels/CalculaIdGridCell.cubin CudaKernels/FindNeighbors.cubin \
	RadixSort/radixsort.o RadixSort/radixsort.cubin Scan/Scan.o Inicializacao/Init.o \
	Visualizacao/Draw.o Visualizacao/Prints.o Calculos/Calculos.o Calculos/SPHKernels.o

# ***********************************************************************************
all:	main

main:	$(OBJFILES)
	@echo "Linking ...."
	$(LINK)  $(CFLAG) $(CPPFLAGS) $(LIBPATH) $(OBJFILES) $(LDFLAGS) $(CUDPPLIB) -o main

.c.o:	$*.h
	@echo "Compiling C code ...."
	$(CXX) -o $*.o -c $(CFLAGS) $(DEFFLAGS) $(INCFLAGS) $*.c

.cpp.o:	$*.h
	@echo "Compiling C++ code ...."
	$(CXX) -o $*.o -c $(CFLAGS)  $(DEFFLAGS) $(INCFLAGS) $*.cpp

.cu.cubin : $*.cu
	@echo "Compiling CUDA files...."
	$(NVCC) -o $*.cubin -c $*.cu $(INCFLAGS) $(NVCCFLAGS)

clean:
	@echo "Clearing ..."
	rm -rf *.o *.bck core *~ main *.cubin CudaKernels/*.cubin Calculos/*.o Inicializacao/*.o Visualizacao/*.o

cleanAll:
	@echo "Clearing All..."
	rm -rf *.o *.bck core *~ main *.cubin RadixSort/*.o RadixSort/*.cubin CudaKernels/*.cubin Scan/*.o Scan/*.cubin Calculos/*.o Inicializacao/*.o Visualizacao/*.o
